Repository navigation
[executorch][native] Keep float scales of int4 ggml embeddings exact - #25049
Open
pytorchbot wants to merge 1 commit into
Open
pytorchbot wants to merge 1 commit into
pytorchbot wants to merge 1 commit into
Conversation
Pull Request resolved: #24975 An int4 weight-only embedding stores its group scales in the PTN as f32 or bf16, and eager dequantizes with those exact values. ggml's Q4_0 blocks hold only an fp16 scale, so the ggml engine rounded each scale to fp16 at load, and 22 of the 219 embedding tests missed eager on CPU and CUDA: `embedding_int4wo_g128.decode_f32`, for one, is off by an RMSE of 1.8e-4 against a tolerance of 1e-5. The PTN carries the exact scales, so the engine was wrong, not the test, and a looser tolerance would hide that. Q4_0 can't take f32 scales without a ggml change, and dequantizing the table to f32 at load would match eager at about 7 times the memory. A linear's matmul reads the scales from inside the blocks, but an embedding only gathers rows and can scale them afterwards. An int4 constant that only `aten.embedding` reads, with a scale that an fp16 round trip changes, now loads as Q4_0 blocks with unit scales, next to an f32 tensor of its group scales. `aten.embedding` gathers rows from both and multiplies them, which matches eager exactly. The f32 scales cost 1 bit per weight at group size 32 and a quarter bit at 128. Every other int4 weight loads as before, with fp16 scales in its blocks: - a weight shared with a linear, as in tied embeddings; - a mutable weight, because an op can rewrite its blocks; - a weight whose scales are all fp16 values, so most bf16 tables stay a single tensor. `q4_affine` now also rejects zero-width int4 weights, which used to fail later as an allocation error. ggml itself is unchanged. Both ggml-CPU CI targets now run the 22 int4 weight-only f32 embedding tests that the previous diff excluded. Authored with Claude Code. Differential Revision: [D130869557](https://our.internmc.facebook.com/intern/diff/D130869557/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D130869557/)! ghstack-source-id: 472753706
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25049
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 9eaa1d4 with merge base fcc9575 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #24975 by @digantdesai
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/digantdesai/204/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/204/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/digantdesai/203/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/204/orig
Differential Revision: D130869557
@diff-train-skip-merge